home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / pv_performAction.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  15.1 KB  |  530 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  December 9, 1996
  22. //    Author:         DSW
  23. //
  24. //  Description:
  25. //      pv_performAction, used currently used by Project Viewer and multilister.
  26. //        callback Performs standard file operations such as Open, Save, Import, etc.
  27. //
  28.  
  29. proc string pv_basename(string $fileName)
  30. //
  31. //    Description:
  32. //        Given a file name, return the basename.
  33. //
  34. {
  35.     string $fName = $fileName;
  36.     if (`about -nt`) {
  37.         $fName = convert($fName);
  38.     }
  39.  
  40.     string $buffer[];
  41.     int $nTokens;
  42.     $nTokens = `tokenize $fName "/" $buffer`;
  43.  
  44.     if ($nTokens > 0) {
  45.         $fName = $buffer[$nTokens-1];
  46.     }
  47.  
  48.     $nTokens = `tokenize $fName "." $buffer`;
  49.     if ($nTokens > 0) {
  50.         $fName = $buffer[0];
  51.     }
  52.     
  53.     return $fName;
  54. }
  55.  
  56. global proc int pv_performAction ( string $theFile, string $fileType )
  57. //
  58. //    Description:
  59. //        get the file name from the finder and use it to perform the
  60. //        desired action.
  61. //
  62. {
  63.     global string $gv_operationMode;
  64.     global string $gFileOptionsString;
  65.     global string $gReplaceReferenceNode;
  66.  
  67.     string    $theFinder;
  68.     string    $activeWS;
  69.     int        $index;
  70.     string    $optionsScript;
  71.     int        $OKToSave;
  72.     string    $result;
  73.     int        $fileExists;
  74.     string    $cmdString;
  75.     string    $translatorOptions;
  76.     int        $status = false;
  77.     
  78.     string $currentDir = `workspace -q -dir`;
  79.     retainWorkingDirectory $currentDir;
  80.  
  81.     int $win32 = `about -nt`;
  82.     int $macOS = `about -mac`;
  83.  
  84.     if ($theFile != "") 
  85.     {
  86.         $fileExists = `file -q -ex $theFile`;
  87.  
  88.         if ($fileType == "Best Guess") 
  89.         {    
  90.             // We need to determine the type.
  91.  
  92.             if ($gv_operationMode == "SaveAs") 
  93.             {
  94.                 if (`optionVar -exists defaultFileSaveType`) 
  95.                 {
  96.                     $fileType = `optionVar -q defaultFileSaveType`;
  97.                 } 
  98.                 else 
  99.                 {
  100.                     $fileType = "mayaBinary";
  101.                 }
  102.             } 
  103.             else if ($gv_operationMode == "ExportAll") 
  104.             {
  105.                 if (`optionVar -exists defaultFileExportAllType`) 
  106.                 {
  107.                     $fileType = `optionVar -q defaultFileExportAllType`;
  108.                 } 
  109.                 else 
  110.                 {
  111.                     $fileType = "mayaBinary";
  112.                 }
  113.             } 
  114.             else if ($gv_operationMode == "ExportActive") 
  115.             {
  116.                 if (`optionVar -exists defaultFileExportActiveType`) 
  117.                 {
  118.                     $fileType = `optionVar -q defaultFileExportActiveType`;
  119.                 }
  120.                 else 
  121.                 {
  122.                     $fileType = "mayaBinary";
  123.                 }
  124.             }
  125.             else 
  126.             {
  127.                 if ($fileExists) 
  128.                 {
  129.                     // We must be reading a file. Get the actual type.
  130.  
  131.                     string $fileTypeList[];
  132.                     $fileTypeList = `file -q -typ $theFile`;
  133.  
  134.                     int $listSize = size($fileTypeList);
  135.                     int $index;
  136.                     for ($index = 0; $index < $listSize; $index++) 
  137.                     {
  138.                         if (`translator -q -rs $fileTypeList[$index]`) 
  139.                         {
  140.                             $fileType = $fileTypeList[$index];
  141.                             break;
  142.                         }
  143.                     }
  144.  
  145.                     // If we got here we had a problem... let's see if we
  146.                     // can't sort it out for the users.
  147.  
  148.                     // Is the file readable?
  149.                     string $fullPath = `workspace -en $theFile`;
  150.                     if ( filetest("-r",$fullPath) == 0 ) 
  151.                     {
  152.                         string $errMsg = "Cannot open " + $fullPath +
  153.                                          ": Permission denied";
  154.                         confirmDialog -m  $errMsg
  155.                             -b "Cancel" -db "Cancel"
  156.                             -parent projectViewerWindow;
  157.                         return $status;
  158.                     }
  159.  
  160.                     // If the file is readable, we just must not understand it.
  161.  
  162.                     if ($fileType == "Best Guess") 
  163.                     {
  164.                         //    Get the file extension. Be sure to remove case to
  165.                         //    simplify comparisons.
  166.                         //
  167.                         string $extension = `match "\\..*$" $theFile`;
  168.                         $extension = `tolower $extension`;
  169.  
  170.                         int $postedDialog = false;
  171.  
  172.                         if (`about -evalVersion`) {
  173.                             //
  174.                             //    Maya Personal Learning Edition.
  175.                             //
  176.                             if ( $extension == ".ma" || $extension == ".mb" ) {
  177.                                 confirmDialog -message "Files created by Maya cannot be opened by Maya Personal Learning Edition."
  178.                                     -button "Cancel" -defaultButton "Cancel"
  179.                                     -parent projectViewerWindow;
  180.                                 $postedDialog = true;
  181.                             }
  182.                         } else {
  183.                             //
  184.                             //    Maya.
  185.                             //
  186.                             if ( $extension == ".mp" ) {
  187.                                 confirmDialog -message "Files created by Maya Personal Learning Edition cannot be opened by Maya."
  188.                                     -button "Cancel" -defaultButton "Cancel"
  189.                                     -parent projectViewerWindow;
  190.                                 $postedDialog = true;
  191.                             }
  192.                         }
  193.  
  194.                         if (!$postedDialog) { 
  195.                             confirmDialog -message "Unrecognized File Type" 
  196.                                 -button "Cancel" -defaultButton "Cancel"
  197.                                 -parent projectViewerWindow;
  198.                         }
  199.                         
  200.                         return $status;
  201.                     }
  202.                 }
  203.             }
  204.         }
  205.         
  206.  
  207.         $translatorOptions = ($fileType+"Options");
  208.         if (`optionVar -exists $translatorOptions`) {
  209.             // Post the new options.
  210.             $gFileOptionsString = `optionVar -q $translatorOptions`;
  211.         } else {
  212.             $gFileOptionsString = "";
  213.         }
  214.         
  215.             
  216.         if ($gv_operationMode == "SaveAs"
  217.                     || $gv_operationMode == "ExportAll"
  218.                     || $gv_operationMode == "ExportActive") {
  219.  
  220.             // We first check to see if the given file has an extension
  221.             // If it does and this does not match the given type, we change
  222.             // the type to be that specified in the extension.
  223.             if ( $fileType == "mayaAscii" || $fileType == "mayaBinary" )
  224.             {
  225.                 string $extension = `match "\\..*$" $theFile`;
  226.                 $extension = `tolower $extension`;
  227.                 if ( $extension == ".ma" && $fileType == "mayaBinary" )
  228.                     $fileType = "mayaAscii";
  229.                 else if ( $extension == ".mb" && $fileType == "mayaAscii" )
  230.                     $fileType = "mayaBinary";
  231.             }
  232.  
  233.             // See if we are overwriting a file.  The NT file browser
  234.             // has already performed this check.
  235.             //
  236.             $OKToSave = 1;
  237.             if (!$win32 && !$macOS)
  238.             {
  239.                 // If we are using default extensions, then we need to
  240.                 // do some special case checking
  241.                 //
  242.                 if (`file -q -de`) {
  243.                     string $oldType[] = `file -q -type`;
  244.  
  245.                     // Turn default extensions off or changing the
  246.                     // type changes the name
  247.                     //
  248.                     file -de 0;
  249.  
  250.                     // Set the appropriate type
  251.                     //
  252.                     file -type $fileType;
  253.  
  254.                     // If both -de and -ex are specified, check for
  255.                     // the existence of the file with the default
  256.                     // extension applied.
  257.                     //
  258.                     $fileExists = `file -q -de -ex $theFile`;
  259.  
  260.                     // Restore the original type
  261.                     //
  262.                     file -type $oldType[0];
  263.  
  264.                     // Restore the default extensions
  265.                     //
  266.                     file -de 1;
  267.                 }
  268.  
  269.                 if ($fileExists && $gv_operationMode == "SaveAs") {
  270.                     $result = `confirmDialog -m "File Exists. Overwrite?" 
  271.                               -b "Yes" -b "Cancel" -db "Cancel"
  272.                               -parent projectViewerWindow`;
  273.                     if ($result == "Yes") {
  274.                         $OKToSave = 1;
  275.                     } else $OKToSave = 0;
  276.                 }
  277.             }
  278.  
  279.             if ($OKToSave) {
  280.                 // Get the icon.
  281.                 if ( $gv_operationMode == "SaveAs" )
  282.                 {
  283.                     file -rename $theFile;    // Rename the file.
  284.                     if (`saveImage -ex fo_saveIcon`) {
  285.                         // This should probably be passed in somehow.
  286.                         saveImage -e -sf $theFile fo_saveIcon;    // Get the save Icon.
  287.                         optionVar -sv defaultFileSaveType $fileType;
  288.                     }
  289.  
  290.                     string $cmd;
  291.                     if ($gFileOptionsString == "") {
  292.                         $cmd = "file -f -save -type \""+$fileType+"\"";
  293.                     } else {
  294.                         $cmd = "file -f -save -options \""+$gFileOptionsString+"\" -type \""+$fileType+"\"";
  295.                     }
  296.                     evalEcho($cmd);
  297.                     // We want the full name as maya knows it for
  298.                     // recent files
  299.                     string $theSavedFile = `file -q -sn`;
  300.                     if ( `about -nt` )
  301.                         $theSavedFile = convert( $theSavedFile );
  302.                     addRecentFile ($theSavedFile, $fileType);
  303.                 } else if ($gv_operationMode == "ExportActive") {
  304.                     //    Set up the export parameters.
  305.                     if (`optionVar -ex exportIncludeInputs`) {
  306.                         if (`optionVar -q exportIncludeInputs`) {
  307.                             file -chn `optionVar -q exportIncludeChannels`;
  308.                             file -ch `optionVar -q exportIncludeHistory`;
  309.                             file -exp `optionVar -q exportIncludeExpressions`;
  310.                             file -con `optionVar -q exportIncludeConstraints`;
  311.                         } else {
  312.                             file -chn false;
  313.                             file -ch false;
  314.                             file -exp false;
  315.                             file -con false;
  316.                         }
  317.                     } // Else don't change the default values.
  318.  
  319.                     //    If the file type is an animation type, then
  320.                     //    set the channels value to true. Animation 
  321.                     //    exporters should set an int optionVar in the
  322.                     //    export options script. The optionVar should be
  323.                     //    set true to always export animation.
  324.                     //
  325.                     string $isAnimOptVar = ($fileType+"AnimationFile");
  326.                     float $channelsValueChanged = false;
  327.                     float $oldChannelsValue = `file -q -chn`;
  328.  
  329.                     if (`optionVar -ex $isAnimOptVar` && 
  330.                         `optionVar -q $isAnimOptVar`) {
  331.                         file -chn true;
  332.                         $channelsValueChanged = true;
  333.                     }
  334.  
  335.                     if (`optionVar -ex exportIncludeShaders`) {
  336.                         if (`optionVar -q exportIncludeShaders`) {
  337.                             file -sh true;
  338.                         } else {
  339.                             file -sh false;
  340.                         }
  341.                     } // Else don't change the default value.
  342.  
  343.                     if (($fileType == "mayaAscii" || $fileType == "mayaBinary")
  344.                         && (`optionVar -ex exportKeepOnlyRef`
  345.                             && `optionVar -q exportKeepOnlyRef`)) {
  346.  
  347.                         // Then we really want to export it as a reference.
  348.                         string $cmd = ("file -type \""+$fileType+"\" ");
  349.  
  350.                         string $clashName;
  351.                         if (`optionVar -exists exportOptionsUseRenamePrefix`) {
  352.                             int $userPrefix = `optionVar -q exportOptionsUseRenamePrefix`;
  353.                             if ($userPrefix && `optionVar -exists exportOptionsRenamePrefix`) {
  354.                                 $clashName = `optionVar -q exportOptionsRenamePrefix`;
  355.                             }
  356.                         }
  357.  
  358.                         if (size($clashName) == 0) {
  359.                             $clashName = pv_basename($theFile);
  360.                         }
  361.  
  362.                         if (size($clashName) > 0) {
  363.                             if (`optionVar -q exportUseNamespacesDuringFileIO`) {
  364.                                 $cmd = $cmd + "-namespace \""+$clashName+"\" ";
  365.                             } else {
  366.                                 $cmd = $cmd + "-rpr \""+$clashName+"\" ";
  367.                             }
  368.                         }
  369.  
  370.                         if ($gFileOptionsString != "") {
  371.                             $cmd = $cmd+"-options \""+$gFileOptionsString+"\" ";
  372.                         }
  373.                         $cmd = $cmd+"-er \""+$theFile+"\"";
  374.                         evalEcho($cmd);
  375.                     } else {
  376.                         file     -op $gFileOptionsString -typ $fileType 
  377.                                 -es $theFile;
  378.                     }
  379.                     optionVar -sv defaultFileExportActiveType $fileType;
  380.  
  381.                     //    Restore the file -channels state, if it was changed.
  382.                     //
  383.                     if ($channelsValueChanged) {
  384.                         file -chn $oldChannelsValue;
  385.                     }
  386.                 } else { // It must be ExportAll.
  387.                     file -op $gFileOptionsString -typ $fileType -ea $theFile;
  388.                     optionVar -sv defaultFileExportAllType $fileType;
  389.                 }
  390.                 $status = true;
  391.             }
  392.         } else if ($gv_operationMode == "CreateReference") {
  393.             // Create a new file to be used as a reference.
  394.             $status = true;
  395.             optionVar -sv defaultFileCreateReferenceType $fileType;
  396.             file -op $gFileOptionsString -typ $fileType -nr $theFile;
  397.         } else if ($fileExists) {
  398.             if ($gv_operationMode == "Open") {
  399.                 
  400.                 $cmdString = "file -f ";
  401.  
  402.                 if (size($gFileOptionsString) > 0) {
  403.                     $cmdString += "-options \""+$gFileOptionsString+"\" ";
  404.                 }
  405.  
  406.                 //    Only add the -executeScriptNodes flag for the negative
  407.                 //    (non-default) case.
  408.                 //
  409.                 if (`optionVar -exists fileExecuteSN`) {
  410.                     if (!`optionVar -q fileExecuteSN`) {
  411.                         $cmdString += (" -esn false ");
  412.                     }
  413.                 }
  414.  
  415.                 //    Only add the -deferReference flag for the positive case.
  416.                 //
  417.                 if (`optionVar -exists fileLoadDeferRef`) {
  418.                     if (`optionVar -q fileLoadDeferRef`) {
  419.                         $cmdString += (" -lad true ");
  420.                     }
  421.                 }
  422.  
  423.                 $cmdString += (    " -typ \""+$fileType+"\" -o \""+$theFile+"\";"+ 
  424.                                 "addRecentFile(\"" + $theFile + "\", \"" +
  425.                                 $fileType + "\")");
  426.  
  427.                 $status = saveChanges($cmdString);
  428.  
  429.             } else if ($gv_operationMode == "Reference") {
  430.                 // Get the option information.
  431.                 string $cmd = "file -r -type \""+$fileType+"\" ";
  432.  
  433.                 if (`optionVar -exists referenceOptionsGrouping`) {
  434.                     if (`optionVar -q referenceOptionsGrouping`) {
  435.                         $cmd = $cmd + "-gr ";
  436.                     }
  437.                 }
  438.  
  439.                 string $clashName;
  440.                 if (`optionVar -exists referenceOptionsUseRenamePrefix`) {
  441.                     int $userPrefix = `optionVar -q referenceOptionsUseRenamePrefix`;
  442.                     if ($userPrefix && `optionVar -exists referenceOptionsRenamePrefix`) {
  443.                         $clashName = `optionVar -q referenceOptionsRenamePrefix`;
  444.                     }
  445.                 }
  446.  
  447.                 if (size($clashName) == 0) {
  448.                     $clashName = pv_basename($theFile);
  449.                 }
  450.  
  451.                 if (size($clashName) > 0) {
  452.                     if (`optionVar -q referenceUseNamespacesDuringFileIO`) {
  453.                         $cmd = $cmd + "-namespace \""+$clashName+"\" ";
  454.                     } else {
  455.                         $cmd = $cmd + "-rpr \""+$clashName+"\" ";
  456.                     }
  457.                 }
  458.  
  459.                 if ($gFileOptionsString != "") {
  460.                     $cmd = $cmd+"-options \""+$gFileOptionsString+"\" ";
  461.                 }
  462.  
  463.                 $cmd = $cmd + "\""+$theFile+"\"";
  464.  
  465.                 evalEcho($cmd);
  466.                 $status = true;
  467.             } else if ($gv_operationMode == "Import") {
  468.                 // Get the option information.
  469.                 string $cmd = "file -import -type \""+$fileType+"\" ";
  470.  
  471.                 if (`optionVar -exists fileOptionsGrouping`) {
  472.                     if (`optionVar -q fileOptionsGrouping`) {
  473.                         $cmd = $cmd+"-gr ";
  474.                     }
  475.                 }
  476.                 if (`optionVar -exists fileOptionsRenameAll`) {
  477.                     if (`optionVar -q fileOptionsRenameAll`) {
  478.                         $cmd = $cmd+"-ra true ";
  479.                     }
  480.                 }
  481.  
  482.                 string $clashName;
  483.                 if (`optionVar -exists fileOptionsUseRenamePrefix`) {
  484.                     int $userPrefix = `optionVar -q fileOptionsUseRenamePrefix`;
  485.                     if ($userPrefix && `optionVar -exists fileOptionsRenamePrefix`) {
  486.                         $clashName = `optionVar -q fileOptionsRenamePrefix`;
  487.                     }
  488.                 }
  489.  
  490.                 if (size($clashName) == 0) {
  491.                     $clashName = pv_basename($theFile);
  492.                 }
  493.  
  494.                 if (size($clashName) > 0) {
  495.                     if (`optionVar -q useNamespacesDuringFileIO`) {
  496.                         $cmd = $cmd + "-namespace \""+$clashName+"\" ";
  497.                     } else {
  498.                         $cmd = $cmd + "-rpr \""+$clashName+"\" ";
  499.                     }
  500.                 }
  501.  
  502.                 if ($gFileOptionsString != "") {
  503.                     $cmd = $cmd+"-options \""+$gFileOptionsString+"\" ";
  504.                 }
  505.                 $cmd = $cmd+"\""+$theFile+"\"";
  506.                 evalEcho($cmd);
  507.                 $status = true;
  508.             } else if ($gv_operationMode == "ReplaceReference") {
  509.                 // Get the option information.
  510.                 string $cmd =    "file -loadReference \""+$gReplaceReferenceNode 
  511.                                 + "\" -type \""+$fileType+"\" ";
  512.  
  513.                 if ($gFileOptionsString != "") {
  514.                     $cmd = $cmd+"-options \""+$gFileOptionsString+"\" ";
  515.                 }
  516.  
  517.                 $cmd = $cmd + "\""+$theFile+"\"";
  518.  
  519.                 evalEcho($cmd);
  520.                 $status = true;
  521.             }
  522.         } else {
  523.             confirmDialog -m "File Does Not Exist. " 
  524.                 -b "OK" -db "OK" -parent projectViewerWindow;
  525.         }
  526.     }
  527.     
  528.     return $status;
  529. }
  530.